package com.ruoyi.sl.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sl.mapper.SlTeamMemberMapper;
import com.ruoyi.sl.domain.SlTeamMember;
import com.ruoyi.sl.service.ISlTeamMemberService;

/**
 * 班组成员Service业务层处理
 * 
 * @author admin
 * @date 2024-06-04
 */
@Service
public class SlTeamMemberServiceImpl implements ISlTeamMemberService 
{
    @Autowired
    private SlTeamMemberMapper slTeamMemberMapper;

    /**
     * 查询班组成员
     * 
     * @param memberId 班组成员主键
     * @return 班组成员
     */
    @Override
    public SlTeamMember selectSlTeamMemberByMemberId(Long memberId)
    {
        return slTeamMemberMapper.selectSlTeamMemberByMemberId(memberId);
    }

    /**
     * 查询班组成员信息
     *
     * @param userName 用户
     * @return 班组成员
     */
    @Override
    public SlTeamMember selectSlTeamMemberByUserName(String userName){
        return slTeamMemberMapper.selectSlTeamMemberByUserName(userName);
    }

    /**
     * 查询班组成员信息
     *
     * @param teamCode 编码
     * @return 班组成员
     */
    @Override
    public List<SlTeamMember> selectSlTeamMemberListByTeamCode(String teamCode){
        return slTeamMemberMapper.selectSlTeamMemberListByTeamCode(teamCode);
    }

    /**
     * 查询班组成员列表
     * 
     * @param slTeamMember 班组成员
     * @return 班组成员
     */
    @Override
    public List<SlTeamMember> selectSlTeamMemberList(SlTeamMember slTeamMember)
    {
        return slTeamMemberMapper.selectSlTeamMemberList(slTeamMember);
    }

    /**
     * 查询班组成员是否已分配
     *
     * @param slTeamMember 班组成员
     * @return true/false
     */
    @Override
    public boolean checkUserUnique(SlTeamMember slTeamMember) {
        SlTeamMember member = slTeamMemberMapper.checkUserUnique(slTeamMember);
        Long memberId = slTeamMember.getMemberId()==null?-1L:slTeamMember.getMemberId();
        if(StringUtils.isNotNull(member) && memberId !=member.getMemberId()){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

        /**
         * 新增班组成员
         *
         * @param slTeamMember 班组成员
         * @return 结果
         */
    @Override
    public int insertSlTeamMember(SlTeamMember slTeamMember)
    {
        slTeamMember.setCreateTime(DateUtils.getNowDate());
        return slTeamMemberMapper.insertSlTeamMember(slTeamMember);
    }

    /**
     * 修改班组成员
     * 
     * @param slTeamMember 班组成员
     * @return 结果
     */
    @Override
    public int updateSlTeamMember(SlTeamMember slTeamMember)
    {
        slTeamMember.setUpdateTime(DateUtils.getNowDate());
        return slTeamMemberMapper.updateSlTeamMember(slTeamMember);
    }

    /**
     * 批量删除班组成员
     * 
     * @param memberIds 需要删除的班组成员主键
     * @return 结果
     */
    @Override
    public int deleteSlTeamMemberByMemberIds(Long[] memberIds)
    {
        return slTeamMemberMapper.deleteSlTeamMemberByMemberIds(memberIds);
    }

    /**
     * 删除班组成员信息
     * 
     * @param memberId 班组成员主键
     * @return 结果
     */
    @Override
    public int deleteSlTeamMemberByMemberId(Long memberId)
    {
        return slTeamMemberMapper.deleteSlTeamMemberByMemberId(memberId);
    }
}
